What optional filters are and how you can use filter scoring to improve relevance.
optionalFilters
score:
brand
attribute has Apple
as its value. If this is the case, the record gets a score of 2 on this filter and 0 otherwise. Finally, it checks the type
attribute to see if it matches tablet
and assigns a score of 1.
In the following records, the first record matches both the brand:Apple<score=2>
and type:tablet
optional filters, which score 2 and 1 (for a total score of 3). However, the second record only matches the brand:Apple<score=2>
optional filter, so the record gets a total score of 2. Therefore, the iPad Pro record shows up higher than the iPhone one.
["color:red<score=2>", "color:blue"]
), the engine checks all nested optional filters and uses the highest matching score.type:-jeans
). The record also matches (it’s not “jeans”), so it scores 1. Adding this to the previous optional filter’s score, the total score for this record is 3.sumOrFiltersScores
sumOrFiltersScores
parameter to a search. This makes the engine add all scores together, regardless of the structure of your filters.
In the preceding example, this means that products that are both “red” and “blue” would show up even higher:
sumOrFiltersScores
parameter only changes the scoring for OR
optional filters, which you create with a nested array of optional filters (optionalFilters: [["attr:val"]]
). The engine always sums AND
filter scores (optionalFilters: ["attr:val1", "attr:val2"]
).optionalFilters
with the filterOnly
modifier, which tells the engine to treat the attribute as a filter instead of a facet. For example:optionalFilters
. For example, it’s preferable to use it with attributes like “brand” rather than “product_name”, as there are usually more unique product names than brands.optionalFilters
as much as possible.